home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
HPAVC
/
HPAVC CD-ROM.iso
/
FNTPAK32.ZIP
/
C.EXE
/
DEMOFNT2.C
< prev
next >
Wrap
C/C++ Source or Header
|
1995-08-16
|
7KB
|
229 lines
/**********************************************************************
DemoFnt2.C Copyright 1994, Rob W. Smetana
Turn Screen Swapping ON if appropriate.
Demonstrate how to load Font Pak fonts from disk.
Demonstrate how to use TryToLoadFont, a LOCAL function, to load
fonts -OR- print an error message (eg., font file not found) and exit.
Run DemoFnt1.C for a demo of how to CALL fonts, and use two fonts
on the screen at once.
*** BEFORE running this, BE SURE the font files Oldeng_5.F16 ***
*** and Script_3.F16 are on the CURRENT drive/directory. ***
**********************************************************************/
#include <font_pak.h> /* for declarations -- PLEASE READ */
/*
Block = 0-3 (EGA) or 0-7 (VGA)
Syntax: LOADFONTFILE (FontFileName, Block);
Syntax: RSWHICHFONTS(LowIntensity, HiIntensity);
Syntax: RSLOADDefault(FontSize, Block); FontSize = 8, 14 or 16
*/
/*
TryToLoadFont is a LOCAL function that loads a font file -OR-
prints an error message and exits.
int TryToLoadFont ();
*/
int GetFontSize (); /* local get-monitor function to detect EGA/VGA
and return size of default font (14/16)
-or- print error message if appropriate */
int main (void)
{
int block1, block2, fontsize, returncode;
char fontfile[64];
/*
We'll load font into blocks 1 and 2 -- leaving the default (0) alone.
*/
block1 = 1;
block2 = 2;
/*
PRE-Load blocks 1 & 2. This will ensure that if we load
a partial font (with NO line draw characters) we'll have
something to draw with.
*/
fontsize = GetFontSize ();
if (fontsize == 0)
return (-99);
RSLOADDEFAULT (fontsize, block1);
RSLOADDEFAULT (fontsize, block2);
printf("\n\n\n\n\n\n\n\n\n\n\n\n");
printf("\n ┌─░░░░░░░░░▒▒▒▒▒▒▒▒▒▒▒▓▓▓▓▓▓▓ Font Pak Pro: Demo ▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▒░░░░░░░░─┐\n");
printf(" ░│ │\n");
printf(" ░│ If you changed line-draw characters they'll differ too. │\n");
printf(" ░│ ╒═══════╕ ╓──╖ ╓───╖ │\n");
printf(" ░│ ┌──────┼─────┐ ╔══════╦═══════╗ ╒═════╧═════╕ │ ║ ─╫───╫────╜ ║ │\n");
printf(" ░│ │ ├──── │ ║ ╚════╗ ╬═╗ │ ╒═════╪═╛ ║ ║ ║ ─rws─ ║ │\n");
printf(" ░│ └──────┼─────┘ ╚═══════════╬══╝ ║ ╘═════╪═════╛ ║ ╙───╫────────╜ │\n");
printf(" ░│ │ ╚════╝ ╘═════════ ╙──────╜ │\n");
printf(" ░└──────────────────────────────────────────────────────────────────────────┘\n");
printf(" ░░░░░░░░░░░░░░░░░░░░░░░░ Press <SPACE> to change fonts ░░░░░░░░░░░░░░░░░░░░░\n");
printf("\n\n\n");
printf("\t\tHere's the default font. Press <SPACE>.");
getch();
/*
Try different fonts below.
Be SURE font files are on the CURRENT path before you run this.
*/
strcpy (fontfile, "script_3.F16");
/*
Here's the direct way to load a font
returncode = LOADFONTFILE (fontfile, block1);
But we'll use a local function to ensure the file's here. If not, exit.
*/
returncode = TryToLoadFont(fontfile, block1);
strcpy (fontfile, "oldeng_5.F16");
returncode = TryToLoadFont(fontfile, block2);
/*
select block 1 -- exclusively
*/
RSWHICHFONTS (block1, block1);
printf("\n\n\t\tHere's the font you loaded into block %d. Press <SPACE>.",block1);
getch();
/*
select block 2 -- exclusively
*/
RSWHICHFONTS (block2, block2);
printf("\n\n\t\tHere's the font you loaded into block %d. Press <SPACE>.",block2);
getch();
/*
Stick the default font back into the blocks we changed.
*/
fontsize = GetFontSize ();
RSLOADDEFAULT (fontsize, block1);
RSLOADDEFAULT (fontsize, block2);
/*
return to block 0 exclusively
*/
block1 = 0;
block2 = 0;
RSWHICHFONTS (block1, block2);
printf("\n\n\t\tAnd back to normal.\n");
return (0);
} /* end main */
/*******************************************************************
Function TryToLoadFont calls LOADFONTFILE.
If an error occurs, it prints a message and ends.
*******************************************************************/
int TryToLoadFont (fontfile, block)
char *fontfile;
int block;
{
int returncode;
returncode = LOADFONTFILE (fontfile, block);
if (returncode != 0) {
printf ("\n\n Error %d occurred loading [%s].. \n\n",returncode, fontfile);
switch (returncode) {
case -99:
printf (" Font [%s] NOT found -or- it wasn't one of our font files. \n\n",fontfile);
break;
case -66:
printf (" malloc failed -- couldn't allocate memory needed to load font.\n\n");
break;
case -77:
printf (" Loading characters beyond 255. Header may be corrupt. Re-save font.\n\n");
break;
case -88:
printf (" File-read failed (should never happen -- bad disk?).\n\n");
break;
}
exit(returncode);
}
return (0);
}
/*******************************************************************
Function: GetFontSize
Purpose: Check for EGA/VGA and return 14 (EGA 8x14), 16 (VGA 8x16)
or 0 if we're not using an EGA/VGA
Print error message and end if no EGA/VGA
Return FontSize for use in other functions
GetMonitor returns an integer (0 - 8) indicating the type of monitor
in use. If two monitors are being used, GetMonitor returns
the type of the primary monitor.
0 = None (no monitor) 3 = EGA (or MultiSync)
4 = Color (CGA) 5 = Monochrome
7 = VGA Monochrome 8 = VGA Color (or MultiSync)
*******************************************************************/
int GetFontSize ()
{
int MonType;
MonType = GETMONITOR();
switch (MonType) {
case 0, 4, 5: /* no monitor, Mono or CGA */
printf ("Sorry. An EGA or VGA monitor is required to run this demo. \n\n");
return (0);
break;
case 3: /* EGA. Set fontsize to 8x14 */
return (14);
break;
case 7, 8: /* VGA. Set fontsize to 8x16 */
return (16);
break;
default:
printf ("Unknown monitor type. Sorry. An EGA or VGA monitor is required to run this. \n\n");
return (0);
break;
}
}